<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HashMap负载因子0.75的设计哲学</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 1rem 1.5rem;
            border-radius: 12px;
            margin: 1.5rem 0;
            position: relative;
            overflow: hidden;
        }
        
        .highlight-box::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: shimmer 3s infinite;
        }
        
        @keyframes shimmer {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            padding: 1.5rem;
            border-radius: 8px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            position: relative;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            background: #007acc;
            color: white;
            padding: 0.25rem 0.75rem;
            border-radius: 4px;
            font-size: 0.75rem;
            font-weight: 600;
        }
        
        .formula-box {
            background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
            padding: 2rem;
            border-radius: 12px;
            text-align: center;
            margin: 2rem 0;
            font-size: 1.25rem;
            font-weight: 600;
            color: #2d3748;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .feature-card {
            background: white;
            border-radius: 12px;
            padding: 1.5rem;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
            border: 1px solid #e2e8f0;
        }
        
        .feature-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
            border-color: #667eea;
        }
        
        .icon-wrapper {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.25rem;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    HashMap负载因子0.75的设计哲学
                </h1>
                <p class="text-xl md:text-2xl opacity-90 leading-relaxed">
                    深入探索Java HashMap中最优雅的数学平衡
                </p>
                <div class="mt-8 flex justify-center space-x-4">
                    <div class="bg-white bg-opacity-20 backdrop-blur-sm rounded-lg px-6 py-3">
                        <i class="fas fa-clock mr-2"></i>
                        <span>阅读时间：15分钟</span>
                    </div>
                    <div class="bg-white bg-opacity-20 backdrop-blur-sm rounded-lg px-6 py-3">
                        <i class="fas fa-layer-group mr-2"></i>
                        <span>深度：高级</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction -->
        <div class="content-card rounded-2xl shadow-xl p-8 md:p-12 mb-8">
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                <span class="drop-cap">你</span>们在日常编程中可能已经多次使用过 HashMap，但未必了解其底层工作原理。为什么 HashMap 的默认负载因子是 0.75？这个问题看似简单，但背后蕴藏着丰富的设计理念和权衡取舍。了解这个概念有助于我们更好地理解 HashMap 的性能和效率，甚至在实际项目中进行相关优化。
            </p>
            
            <div class="highlight-box">
                <i class="fas fa-lightbulb text-2xl mb-2"></i>
                <p class="text-lg font-medium">
                    负载因子决定了哈希表在扩容之前可以填充的程度。具体来说，当哈希表中的条目数量达到负载因子与当前容量的乘积时，哈希表就会进行扩容。默认负载因子为 0.75 代表哈希表在达到 75% 的填充度时会进行扩容。
                </p>
            </div>
        </div>

        <!-- Visual Representation -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-6">
                负载因子的可视化理解
            </h2>
            <div class="mermaid">
                graph LR
                    A[HashMap容量] -->|75%填充| B[触发扩容]
                    B --> C[容量翻倍]
                    C --> D[重新哈希]
                    D --> E[元素重新分布]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style B fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#f5576c,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#4facfe,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Core Concepts -->
        <div class="grid md:grid-cols-2 gap-6 mb-8">
            <div class="feature-card">
                <div class="icon-wrapper">
                    <i class="fas fa-balance-scale"></i>
                </div>
                <h3 class="text-xl font-bold text-gray-800 mb-3">空间与时间的平衡</h3>
                <p class="text-gray-600 leading-relaxed">
                    0.75的负载因子是空间利用率和时间效率之间的黄金平衡点。过低会浪费内存，过高会增加哈希冲突。
                </p>
            </div>
            
            <div class="feature-card">
                <div class="icon-wrapper">
                    <i class="fas fa-chart-line"></i>
                </div>
                <h3 class="text-xl font-bold text-gray-800 mb-3">性能优化</h3>
                <p class="text-gray-600 leading-relaxed">
                    通过控制扩容时机，确保HashMap在大多数情况下都能保持O(1)的时间复杂度。
                </p>
            </div>
        </div>

        <!-- Formula Section -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-6">
                负载因子的数学定义
            </h2>
            
            <div class="formula-box">
                <p class="mb-2">负载因子（Load Factor）= </p>
                <p class="text-2xl">元素数量 ÷ 哈希表容量</p>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6 mt-8">
                <div class="bg-gray-50 rounded-lg p-6">
                    <h4 class="font-bold text-lg mb-3 text-gray-800">
                        <i class="fas fa-info-circle text-blue-500 mr-2"></i>
                        扩容触发条件
                    </h4>
                    <p class="text-gray-600">
                        当元素数量 ≥ 容量 × 负载因子时，HashMap会自动扩容到原来的2倍。
                    </p>
                </div>
                
                <div class="bg-gray-50 rounded-lg p-6">
                    <h4 class="font-bold text-lg mb-3 text-gray-800">
                        <i class="fas fa-calculator text-green-500 mr-2"></i>
                        实例计算
                    </h4>
                    <p class="text-gray-600">
                        初始容量16，负载因子0.75，当元素达到12个（16×0.75）时触发扩容。
                    </p>
                </div>
            </div>
        </div>

        <!-- Performance Analysis -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-6">
                不同负载因子的性能对比
            </h2>
            
            <div class="mermaid">
                graph TD
                    A[负载因子选择] --> B[0.5 - 低负载]
                    A --> C[0.75 - 默认值]
                    A --> D[0.9 - 高负载]
                    
                    B --> B1[频繁扩容]
                    B --> B2[低冲突率]
                    B --> B3[内存浪费]
                    
                    C --> C1[平衡扩容]
                    C --> C2[适中冲突]
                    C --> C3[空间时间均衡]
                    
                    D --> D1[少量扩容]
                    D --> D2[高冲突率]
                    D --> D3[内存高效]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style C3 fill:#4facfe,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Practical Examples -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-6">
                实际应用中的负载因子调整
            </h2>
            
            <div class="space-y-6">
                <div>
                    <h3 class="text-xl font-bold text-gray-800 mb-3">
                        <i class="fas fa-rocket text-purple-500 mr-2"></i>
                        高性能场景
                    </h3>
                    <p class="text-gray-600 mb-4">
                        在实时数据处理系统中，对响应时间